#include "eanimationset.h"
#include "eanimation.h"

EAnimationSet::EAnimationSet()
{
}

EAnimationSet::~EAnimationSet()
{
}

bool EAnimationSet::addAnimation(const std::string &name, boost::shared_ptr<EAnimation> anim)
{
    if(m_anims.find(name) != m_anims.end()) return false;
    m_anims[name] = anim;
    return true;
}

bool EAnimationSet::setCurrentAnimation(const std::string &name)
{
    if(m_anims.find(name) == m_anims.end()) return false;

    if(m_currentAnim.lock())
    {
        m_currentAnim.lock()->exit();
    }

    m_currentAnim = m_anims[name];

    m_currentAnim.lock()->enter();
    return true;
}

boost::shared_ptr<EAnimation> EAnimationSet::currentAnimation() const
{
    Q_ASSERT(m_currentAnim.lock());
    return m_currentAnim.lock();
}

void EAnimationSet::update(float dt)
{
    currentAnimation()->update(dt);
}
